package user_news

import (
	models "HeadLineNews/proto_models/app/user_news_model"
	"HeadLineNews/resp"
	"github.com/gin-gonic/gin"
)

type Server interface {
	UserRetrieveNewsHandler(c *gin.Context)
	UserListNewsHandler(c *gin.Context)
}

type server struct {
	ctx  Ctx
	repo Repo
}

func NewServer() Server {
	return &server{
		ctx:  NewCtx(),
		repo: NewRepo(),
	}
}

// UserRetrieveNewsHandler 用户检索新闻
func (s *server) UserRetrieveNewsHandler(c *gin.Context) {
	p, err := s.repo.UserRetrieveUser(c)
	if err != nil {
		return
	}
	resp.Success(c, p)
}

// UserListNewsHandler 用户展示新闻目录
func (s *server) UserListNewsHandler(c *gin.Context) {
	p, err := s.ctx.ParseParamUserListNews(c)
	if err != nil {
		return
	}
	var data *models.ResponseUserListNews
	if data, err = s.repo.UserListNews(c, p); err != nil {
		return
	}
	resp.Success(c, data)
}
